<!--合作三年以上的班组-->

<template>
  <div>
    <div :bordered="false" style="over-flow:scroll">
      <div>
        <a-row>
          <!--          <a-table :md="24" :sm="19">-->
          <div class="table-operator">
            <a-row>
              <a-col :md="24" :sm="24">
                <a-button    v-if="type=='add' || type=='edit'|| type=='share'"   type="primary"  @click="goAdd()">新增班组</a-button>
                <a-button   v-if="type=='add' || type=='edit'|| type=='share'"   type="info" :disabled="groupList.length == 0"  @click="goDel()">删除</a-button>
              </a-col>
            </a-row>
          </div>
          <a-table
                  :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                  :columns="columns" bordered
                  :data-source="groupList">
            
            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
            
            <span slot="action" slot-scope="text, record">
                <template>
                <a   v-if="type=='add' || type=='edit'|| type=='share'"  @click="handleEdit(record)">编辑</a>
                </template>
            </span>
          </a-table>
        </a-row>
      </div>
    </div>
    <a-modal width="1000px" v-model="visible" :title="title" >
      <template slot="footer">
        <a-button key="back" @click="handleCancel">
          取消
        </a-button>
        <a-button :disabled="type=='view'"  key="submit" type="primary" :loading="loading" @click="handleOk">
          确定
        </a-button>
      </template>
      <a-form :model="form">
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="班组类别"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'"  v-model="form.type"  placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="班组长姓名及联系方式"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'"  v-model="form.nameAndPhone"  placeholder="请输入" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="工人人数（人）"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInputNumber :disabled="type=='view'" :isInt='true' :min='0'  v-model="form.count"  placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="合作年限"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInputNumber  :min='0' :disabled="type=='view'"   v-model="form.time"  placeholder="请输入" />
              <!-- <a-date-picker :disabled="type=='view'"  v-model="form.time" @change="changeTime"></a-date-picker> -->
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="工人主要来源地"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'"  v-model="form.source"  placeholder="请输入" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-modal>
  </div>
</template>

<script>
  import { STable } from '@/components'
  import { getTeamList ,addTeamList ,editTeamList, deleteTeamList} from '@/api/subcontractors/labour'

  const columns = [
    {
      title: '序号',
      width:65,
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '班组类别',
      dataIndex: 'type',
      ellipsis: true,
    },
    {
      title: '班组长姓名及联系方式',
      dataIndex: 'nameAndPhone',
      ellipsis: true,
    },
    {
      title: '工人人数',
      dataIndex: 'count',
      ellipsis: true,
    },
    {
      title: '合作年限',
      dataIndex: 'time',
      ellipsis: true,
    },
    {
      title: '工人主要来源地',
      dataIndex: 'source',
      ellipsis: true,
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      scopedSlots: { customRender: 'action' }
    }
  ]
  export default {
  name:'a'+Date.now(),
    props: {
      labourList: {
        type: [Object, Array],
        default() {
          return {}
        }
      }
    },
    components:{
    },
    data(){
      this.columns = columns
      return{
        visible:false,
        id:'',
        subcontractorId:1,
        title:'',
        type:'',
        disabled:false,
        loading:false,
        form:{
          type:'',
          nameAndPhone:'',
          count:'',
          time:'',
          source:'',
        },
        groupList:[],
        selectedRowKeys:[],
        selectedRows:[],
        selectId:[],
        addInvestigateId:''
      }
    },
    created() {
      this.addInvestigateId = JSON.parse(sessionStorage.getItem("addInvestigateId"))
      this.type=this.$route.query.type
      if(this.type == 'share'){
        this.id = this.addInvestigateId
      }else{
        this.id = this.$route.query.id || this.addInvestigateId
      }
      this.getGroup()
    },
    methods:{
      onSelectChange(selectedRowKeys,selectedRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectedRows = selectedRows
      },
      getGroup(){
        getTeamList({id:this.id}).then((res)=>{
          this.groupList=res.data
        })
      },
      search(){
        this.$refs.table.refresh(true)
      },
      goAdd(){
        this.form={}
        this.visible=true
        this.title='新增合作三年以上的班组'
      },
      changeTime(value,dateString){
        this.form.time = dateString
      },
      goDel(){
        let _this = this
        if(_this.selectedRows.length==1){

          this.$confirm({
            title: '警告提醒！',
            content: '确定删除？',
            okType: 'danger',
            onOk() {
              deleteTeamList({ids:_this.selectedRows[0].id,lsebId:_this.labourList.subcontractorBase.evaluationId}).then((res)=>{
                if(res.code=='200'){
                  _this.getGroup()
                  _this.$message.success("删除成功")
                  _this.selectedRows=[]
                  _this.selectedRowKeys=[]
                }
              })
            },
            onCancel() {
              console.log('Cancel');
            },
          });
        }else if(_this.selectedRows.length>1){
          _this.selectId=[]
          _this.selectedRows.forEach((item)=>{
            _this.selectId.push(item.id)
          })
          this.$confirm({
            title: '警告提醒！',
            content: '确定删除？',
            okType: 'danger',
            onOk() {
              deleteTeamList({ids:_this.selectId.join(","),lsebId:_this.labourList.subcontractorBase.evaluationId}).then((res)=>{
                if(res.code=='200'){
                  _this.getGroup()
                  _this.$message.success("删除成功")
                  _this.selectedRows=[]
                  _this.selectedRowKeys=[]
                }
              })
            },
            onCancel() {
              console.log('Cancel');
            },
          });
        } else if(_this.selectedRows.length == 0){
			_this.$message.error("请选择要删除的内容")
		}
      },
      handleSub(){

      },
      handleEdit(record){
        this.visible = true
        this.title='编辑合作三年以上的班组'
        // this.form = record
		this.form = JSON.parse(JSON.stringify(record))

      },
      handleOk(){
        this.visible = false
        this.form.lsebId = this.labourList.subcontractorBase.evaluationId
        if(this.form.id){
          editTeamList(this.form).then((res)=>{
            if(res.code=='200'){
              this.$message.success("编辑成功")
              this.getGroup()
            }
          })
        }else{
          addTeamList(this.form).then((res)=>{
            if(res.code=='200'){
              this.$message.success("新增成功")
              this.getGroup()
            }
          })
        }
      },
      handleCancel(){
        this.visible = false
      },
      handleAdd(){

      }
    }
  }
</script>

<style scoped>
  .input{
    width:100%
  }
  /deep/ .ant-table-pagination.ant-pagination{
       display:none
     }
</style>
